package com.example.springioc.config;


import com.example.springioc.dao.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class UserConfiguration {
    /*
            使用@Bean将UserInfo存入spring中
            @Bean要配合五大类注解使用
     */

    // @Primary // 当存在多个相同类型的Bean注⼊时，加上@Primary注解，来确定默认的实现.
    @Bean("u1") // 给对象重名名
    public UserInfo userInfo1() {
        UserInfo userInfo = new UserInfo();
        userInfo.setAge(18);
        userInfo.setName("zhangsan");
        return userInfo;
    }

    @Bean("u2")
    public UserInfo userInfo2() {
        UserInfo userInfo = new UserInfo();
        userInfo.setAge(20);
        userInfo.setName("lisi");
        return userInfo;
    }

    public void fun(){
        System.out.println("hello,userConfiguration");
    }


}
